//
//  InputView.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/1.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit
//@objc protocol ReportTextState {
//    func canNotPass(reson : String) -> Void
//}
class InputView: BaseView,UITextFieldDelegate {
    private let nameLbl = UILabel.init()
    var contentField = UITextField.init()
    
    var title = "" {
        didSet{
            nameLbl.text = title
        }
    }
    
    var placeHolder = "" {
        didSet{
            contentField.placeholder = placeHolder
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        self.layer.cornerRadius = YXCornerRadius
        self.layer.borderWidth = YXHeightScale
        self.layer.borderColor = UIColor.defaultBorderColor().cgColor
        nameLbl.textColor = UIColor.colorWithHexString(hex: "2c2c2c")
        nameLbl.font = UIFont.systemFont(ofSize: 28 * YXWidthScale)
        contentField.textColor = UIColor.colorWithHexString(hex: "2c2c2c")
        contentField.font = UIFont.systemFont(ofSize: 28 * YXWidthScale)
        contentField.delegate = self
        self.addSubview(nameLbl)
        self.addSubview(contentField)
    }
    
    func content() -> String {
        guard contentField.text != nil else {
            return ""
        }
        return contentField.text!
    }
    
    //只检查字符串是否大于6位
    func isPhoneNumber() -> Bool {
        let result = NumberChecker.phoneNumCheck(phone: contentField.text)
        return result
    }
    
    func isPass() -> Bool {
        let result = NumberChecker.isPass(num: contentField.text)
        return result
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let size = "账号".StringSize(font: nameLbl.font)
        nameLbl.frame = CGRect.init(x: 32.0 * YXWidthScale, y: 32.0 * YXHeightScale, width: size.width, height: size.height)
        contentField.frame = CGRect.init(x: nameLbl.right() + 32.0 * YXWidthScale, y: nameLbl.top(), width: self.width() - (nameLbl.right() + 32.0 * YXWidthScale), height: nameLbl.height());
    }
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        return true
    }
    
    //textdelegate
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
